<?php
/**
*Smarty plugin
*@Liu Zhongjie
*@Beijing Arouter Co.Ltd
*@2007-2-12
**/

/**
* Smarty {html_textarea} function plugin
*
* Type:    function<br>
* Name:    html_textarea<br>
* Date:    Feb 12,2007<br>
* Input:<br>
*         -name        = Textarea name.(string).
*         -rows        = Textarea rows.(integer)
*         -cols        = Textarea cols.(integer)
*         -class       = Class CSS style.(string).
*
* Examples:
* <pre>
* {html_textarea name="content" rows=5 cols=20 class="text"}
* </pre>
* @param array
* @param Smarty
* @return string
**/

function smarty_function_html_textarea ($params, &$smarty)
{
	require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
	
	$name         = NULL;
	$rows         = NULL;
	$cols         = NULL;
	$class        = NULL;
    $label        = false;
    $content      = NULL;
    
    foreach ($params as $_key=>$_value) {
        switch ($_key) {
            case 'name':
            case 'class':
            case 'content':
                $$_key = (string)$_value;
                break;

            case 'rows':
            case 'cols':
                $$_key = (int)$_value;
                break;

            case 'label':
                $$_key = (bool)$_value;
                break;
        }
    }
  
    if($label) $output = "<label>";
    else $output = "";
    $output .= '<textarea name="' . smarty_function_escape_special_chars($name) . '" rows="' 
    . smarty_function_escape_special_chars($rows) .'" cols="' 
    . smarty_function_escape_special_chars($cols) .'" class="' 
    . smarty_function_escape_special_chars($class) . '" ';

    $output .=">\n";
    $output .=$content;
    $output .="</textarea>";
    
    if($label) $output .= "</label>";
    
    return $output;
}
?>